/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controle;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Fellipe
 */
@WebServlet(name = "trataListaUsuario", urlPatterns = {"/trataListaUsuario"})
public class trataListaUsuario extends Comando {

    private String user;
    private String senha;
    private String url;
     
    private Connection conexao;
  
    public void execute() throws ServletException, IOException, SQLException {
        getResponse().setContentType("text/html;charset=UTF-8");
        PrintWriter out = getResponse().getWriter();
        try {
 
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            Connection conexao = DriverManager.getConnection("jdbc:oracle:thin:@aula.inf.ifrs.edu.br:XE", "b206", "senhamarota");
            Statement stmt = conexao.createStatement();
            String sql = "SELECT * FROM USUARIO";
            ResultSet rs = stmt.executeQuery(sql);
                         
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet trataListaUsuarios</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<table>");
            while (rs.next()) {
                int id = rs.getInt(1);
                String nome = rs.getString(2);
                String login = rs.getString(3);
                String senha = rs.getString(4);
                String data = rs.getString(5);
                 
                out.println("<TR>");
                out.println("<TD> Nome :" + nome + " </TD>");
                out.println("<TD> Login :" + login + " </TD>");
                out.println("<TD> Senha :" + senha + " </TD>");
                out.println("<TD> Data criação:" + data + " </TD>");
                out.println("</TR>"); 
            }
            out.println("</table>");
            out.println("</body>");
            out.println("</html>");
            conexao.close();
        } catch (SQLException ex) {
            throw new ServletException(ex);
 
        }
    }

}
